<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>登录到 FuXiaoHei.Me</title>
    <link rel="stylesheet" href="/admin/css/global.css" media="all" type="text/css"/>
    <link rel="stylesheet" href="/admin/css/style.css" media="all" type="text/css"/>
    <script type="text/javascript" src="/admin/js/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="/admin/js/jquery.form.js"></script>
</head>
<body>
<div id="header">
    <div id="header-top-color" class="clear">
        <div class="red left"></div>
        <div class="orange left"></div>
        <div class="green left"></div>
        <div class="blue left"></div>
        <div class="purple left"></div>
    </div>
    <div class="container">
        <h1 id="logo" class="left h1"><a href="/">FuXiaoHei.Me</a></h1>
        <span id="logo-desc">傅小黑的自留地</span>
    </div>
</div>
<div id="login">
    <div id="login-result-message">
        <div class="message success hide">登录成功，正在进入...</div>
        <div class="message error hide">登录出现错误：{msg}</div>
    </div>
    <div class="container" id="login-container">
        <div id="login-header" class="clear">
            <h1 class="h1 left">登录到 FuXiaoHei.Me</h1>
        </div>
        <div id="login-form-container" class="left">
            <form id="login-form" class="form" action="/login" method="post">
                <p class="item">
                    <label for="login-email">邮箱</label>
                    <input id="login-email" class="ipt" type="email" name="email" required="required"/>
                </p>
                <p class="item">
                    <label for="login-password">密码</label>
                    <input id="login-password" class="ipt" type="password" name="password" required="required"/>
                </p>
                <p class="item">
                    <span class="chk-span">
                        <input class="chk" type="checkbox" checked name="remember" value="7"/>
                        <span class="chk-word">记住登陆信息一周</span>
                    </span>
                </p>
                <p class="divide"></p>
                <p class="item">
                    <a class="left" id="forget-password" href="/user/forget">Forget Password ?</a>
                    <input class="btn right" id="login-submit" type="submit" value="Sign in to FuXiaoHei.Me"/>
                </p>
            </form>
        </div>
        <div id="login-secondary" class="right">
            <p class="social-login-title">或者您还可以</p>
            <div>微博登录，没申请</div>
            <div>GitHub登录，还没看</div>
            <div>QQ登录，下辈子</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var errorFunc = function () {
            var $err = $('#login-result-message').find(".error");
            $err.slideDown(100);
            if (window.$timeout) {
                clearTimeout(window.$timeout);
            }
            window.$timeout = setTimeout(function () {
                var $btn = $('#login-submit');
                $err.slideUp(100).text("登录出现错误：{msg}");
                if ($btn.hasClass("loading")) {
                    $btn.removeClass("loading").removeAttr("disabled");
                }
            }, 2000);
        };
        var loadingFunc = function () {
            var $btn = $('#login-submit');
            $btn.addClass("loading").attr("disabled", true);
        };
        var successFunc = function (json) {
            if (!json.res) {
                var $err = $('#login-result-message').find(".error");
                var text = $err.text().toString().replace("{msg}", json.msg);
                $err.text(text);
                errorFunc();
                return;
            }
            $('#login-submit').remove();
            $('#login-result-message').find(".success").slideDown(100);
            setTimeout(function () {
                window.location.href = "/admin/home";
                localStorage.setItem("real_name", !json.user.real_name ? json.user.user : json.user.real_name);
            }, 1500);
        };
        $('#login-form').ajaxForm({
            dataType: "json",
            beforeSubmit: loadingFunc,
            error: errorFunc,
            success: successFunc
        });
    });
</script>
</body>
</html>